<%-- 
    Document   : viewUser
    Created on : Apr 30, 2011, 8:49:02 PM
    Author     : christophe
--%>

<%@page import="java.util.List"%>
<%@page import="com.garagesale.data.User"%>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@include file="/WEB-INF/jspf/tagImports.jspf" %>

<!-- The following page directive is needed for c:out to work properly.. otherwise,  -->
<!-- you get the following error: "According to TLD or attribute directive in tag file, attribute var does not accept any..." -->

<html:html lang="true">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>View User</title>
    </head>

    <tags:menu />
    <div id ="content">
        <tags:body>
        <h2>Welcome</h2>
            <c:set var="user" value="${sessionScope.user}" />
            <br />
            <tags:textDisplay labelName="First Name:" textValue="${user.firstName}" />
            <tags:textDisplay labelName="Last Name:" textValue="${user.lastName}" />
            <tags:textDisplay labelName="Username:" textValue="${user.username}" />
            <tags:textDisplay labelName="Email Address:" textValue="${user.emailAddress}" />

            <br />

            <h2>Items for Sale</h2>
            <table style="border-style: solid;">
                <tr style="border-style: inherit;">
                    <th>Name</th>
                    <th>Description</th>
                    <th>Price</th>
                    <th>Category</th>
                    <th>View</th>
                    <th>Delete</th>
                </tr>
                <c:forEach var="item" items="${user.itemsForSellerUserID}" >
                    <tr>
                        <c:url var="viewItemUrl" value="/user/viewItem.do">
                            <c:param name="itemID" value="${item.itemID}" />
                        </c:url>

                        <c:url var="deleteItemUrl" value="/user/saveItem.do">
                            <c:param name="itemID" value="${item.itemID}" />
                            <c:param name="action" value="delete" />
                        </c:url>

                        <td><c:out value="${item.name}" /></td>
                        <td><c:out value="${item.description}" /></td>
                        <td><c:out value="${item.salePrice}" /></td>
                        <td style="color: ${item.itemCategory.labelColor}" ><c:out value="${item.itemCategory.name}" /> </td>
                        <td><a href="${viewItemUrl}">View Item </a> </td>
                        <td>
                            <c:choose>
                                <c:when test="${item.userByBuyerUserId ne null}">
                                    <span>Already Sold!</span>
                                </c:when>
                                <c:when test="${item.shoppingCart ne null}">
                                    <span>Someone wants to buy this</span>
                                </c:when>
                                <c:otherwise>
                                    <a href="${deleteItemUrl}">Delete Item </a>
                                </c:otherwise>
                            </c:choose>

                        </td>

                    </tr>
                </c:forEach>
            </table>


            <h2>Items Already Purchased</h2>
            <table style="border-style: solid;">
                <tr style="border-style: inherit;">
                    <th>Name</th>
                    <th>Description</th>
                    <th>Price</th>
                    <th>Category</th>
                    <th>View</th>
                </tr>
                <c:forEach var="item" items="${user.itemsForBuyerUserID}" >
                    <tr>
                        <c:url var="viewItemUrl" value="/user/viewItem.do">
                            <c:param name="itemID" value="${item.itemID}" />
                        </c:url>
                        <td><c:out value="${item.name}" /></td>
                        <td><c:out value="${item.description}" /></td>
                        <td><c:out value="${item.salePrice}" /></td>
                        <td style="color: ${item.itemCategory.labelColor}" ><c:out value="${item.itemCategory.name}" /> </td>
                        <td><a href="${viewItemUrl}">View Item </a> </td>
                    </tr>
                </c:forEach>
            </table>


            <h2>Items in Cart</h2>
            <table style="border-style: solid;">
                <tr style="border-style: inherit;">
                    <th>Name</th>
                    <th>Description</th>
                    <th>Price</th>
                    <th>Category</th>
                    <th>View</th>
                    <th>Remove From Cart</th>
                </tr>
                <logic:iterate length="1" name="user" property="shoppingCarts" scope="session" id="cart">
                    <c:forEach var="item" items="${cart.items}" >
                        <tr>
                            <c:url var="viewItemUrl" value="/user/viewItem.do">
                                <c:param name="itemID" value="${item.itemID}" />
                            </c:url>
                            <c:url var="removeFromCartUrl" value="/user/removeItemFromCart.do">
                                <c:param name="itemID" value="${item.itemID}" />
                                <c:param name="action" value="delete" />
                            </c:url>

                            <td><c:out value="${item.name}" /></td>
                            <td><c:out value="${item.description}" /></td>
                            <td><c:out value="${item.salePrice}" /></td>
                            <td style="color: ${item.itemCategory.labelColor}" ><c:out value="${item.itemCategory.name}" /> </td>
                            <td><a href="${viewItemUrl}">View Item </a> </td>
                            <td><a href="${removeFromCartUrl}">Remove From Cart</a></td>
                        </tr>
                    </c:forEach>
                </logic:iterate>
            </table>

        </tags:body>
    </div>
    <div id = "footer">
        <span>
            &nbsp;All rights reserved Garage Sale 2011 | Legal | Privacy Policy
        </span>
        <br><br>
        <img alt="" src="../../images/b1.gif">
        <img alt="" src="../../images/b2.gif" style="margin:0px 5px 0px 5px">
        <img alt="" src="../../images/b3.gif">
    </div>
</html:html>
